<%--
  @author Kusal Samarakoon
  @author Supun Viraj Rathnayaka
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<script type="text/javascript" src="${pageContext.request.contextPath}/js/dateSelector.js"></script>
<script src="${pageContext.request.contextPath}/js/landRegistration/longTermLease.js" type="text/javascript"></script>
<script type="text/javascript">


</script>
<script language="javascript">

    $(document).ready(function () {
        validateDetails();
    });

    function validateDetails() {

        $('#referenceNo').rules("add", {
            required: true

        });
        $('#validityPeriod').rules("add", {
            required: true

        });
        $('#annualRental').rules("add", {
            required: true

        });
        $('#annualTax').rules("add", {
            required: true

        });

        $('#lastValuationPeriodStart').rules("add", {
            required: true

        });
        $('#lastValuationPeriodEnd').rules("add", {
            required: true

        });
        $('#valuationAmount').rules("add", {
            required: true

        });

        $('#leaseStartingDate').rules("add", {
            isDateFormated: true,
            required: true

        });

//        $('#leaseExpiringDate').rules("add", {
//            isDateFormated: true
//        });

        $('#name').rules("add", {
            required: true

        });
    }

    function disableInstitute() {
        var fields = new Array(
                'name',
                'address',
                'nic',
                'mobile',
                'landPhone',
                'email',
                'fax'
        );
        enableFields(fields);
    }

    $(function () {
       // alert($("input#editMode").val()) ;
        if ($("input#userRole").val() != "SC" || $("input#editMode").val() == 2 ) {
            disableAlienationFields();
        }
    });

    function disableAlienationFields() {
        var fields1 = new Array(
                'referenceNo',
                'leaseUsagePrimaryId',
                'leaseUsageSecondaryId',
                'validityPeriod',
                'leaseStartingDate',
                'annualRental',
                'annualTax',
                'arrearsAmount',
                'paidAmount',
                'lastValuationPeriodStart',
                'lastValuationPeriodEnd',
                'valuationAmount',
                'clientType0',
                'clientType1',
                'name',
                'address',
                'nic',
                'mobile',
                'landPhone',
                'email',
                'fax',
                'valuationOptionId0',
                'valuationOptionId1',
                'valuationOptionId2',
                'lotNumberAlienation',
                'arrearsTax',
                'paidTax',
                'valuationPercentage'
        );
        disableFields(fields1);
    }

    $(function () {
        var holderPersonHtml = $('#holderPerson').html();
        var holderInstituteHtml = $('#holderInstitute').html();

        /*if ($('#state').val() == '') {
         $('#clientType1').attr('checked', true);
         }*/
        $('#clientType0').bind('click', function () {
            $('#holderPerson').html(' ');
            $('#holderInstitute').html(holderInstituteHtml);
        });
        $('#clientType1').bind('click', function () {
            $('#holderInstitute').html(' ');
            $('#holderPerson').html(holderPersonHtml);
        });
        if ($('#clientType0').is(':checked')) {
            $('#holderPerson').html(' ');
            $('#holderInstitute').html(holderInstituteHtml);
        } else if ($('#clientType1').is(':checked')) {
            $('#holderInstitute').html(' ');
            $('#holderPerson').html(holderPersonHtml);
        }

        if ($('#state').val() == 'DATA_ENTRY') {
            enableFields(new Array('clientType0', 'clientType1'));
        }

        $('#valuePercent').change(function() {
            if ($(this).is(':checked')) {
                $("#valuationPercentage").attr("disabled",false);
            } else {
                $("#valuationPercentage").attr("disabled",true);
            }
        });

        if($('#c-type').val()==0){
            $('input#clientType0').trigger( "click" );
        }

    });

    function calculateTax(){
        var valuation = $('#valuationAmount').val();
        var percent = $('#taxPercentage').val();
        var tax = (parseFloat(valuation) * parseFloat(percent))/100;
        $('#annualRental').val(valuation);
        $('#annualTax').val(tax);
    }
</script>


<div id="tabs">
    <ul>
        <li><s:a href="#long-term-lease-details"><s:label value="Lease Detail"/></s:a></li>
        <li><s:a href="#personal-details"><s:label value="%{getText('holder_details.label')}"/></s:a></li>
        <li><s:a href="#occupier-details"><s:label value="%{getText('occupier_details.label')}"/></s:a></li>
    </ul>
    <div id="long-term-lease-details">
        <table class="width-100">
            <tr>
                <td><s:label value="%{getText('lease_no.label')}"/><span class="mandatory-field"></span></td>
                <td><s:textfield id="referenceNo" name="alienation.referenceNo" cssClass="width-200-px"/></td>
                <td><s:label value="%{getText('lot_no.label')}"/></td>
                <td><s:textfield name="alienation.leaseDetail.lotNumber" id="lotNumberAlienation" cssStyle="width: 200px;"/></td>
            </tr>

            <tr>
                <td><s:label value="Lease Objective of Usage (Primary)"/></td>
                <td colspan="3"><s:select id="leaseUsagePrimaryId" name="alienation.leaseUsagePrimary.id" list="leaseUsageList"
                                          headerKey="0"
                                          headerValue="%{getText('select.label')}" cssClass="width-200-px"/></td>
            </tr>

            <tr>
                <td><s:label value="Lease Objective of Usage (Secondary)"/></td>
                <td colspan="3"><s:select id="leaseUsageSecondaryId" name="alienation.leaseUsageSecondary.id" list="leaseUsageList"
                                          headerKey="0"
                                          headerValue="%{getText('select.label')}" cssClass="width-200-px"/></td>
            </tr>

            <tr>
            <td><s:label value="Validity Period (Years)"/><span class="mandatory-field"></span></td>
            <td><s:textfield id="validityPeriod" name="alienation.leaseDetail.validityPeriod"
                             cssClass="width-200-px"/></td>
            </tr>
            <tr>
                <td><s:label value="Lease Starting Date"/> <s:label
                        value="%{getText('date_format.label')}" cssClass="date-format"/><span
                        class="mandatory-field"></span></td>
                <td><s:textfield id="leaseStartingDate" name="alienation.leaseDetail.leaseStartingDate"
                                 onclick="selectDate('leaseStartingDate')"
                                 cssClass="width-200-px" onKeyPress="return dateNumbersOnly(event,true)"/></td>

                <td colspan="2"></td>

            </tr>

            <tr>
                <td><s:label value="Last Valuation Amount"/><span class="mandatory-field"></span></td>
                <td colspan="3"><s:textfield id="valuationAmount" name="alienation.valuation.valuationAmount"
                                             cssClass="width-200-px" onKeyPress="return dateNumbersOnly(event,true)" onchange="calculateTax()"/>

                </td>
            </tr>

            <tr>
                <td><s:label value="Last Valuation Period Start"/><span class="mandatory-field"></span></td>
                <td><s:textfield id="lastValuationPeriodStart" name="alienation.valuation.lastValuationPeriodStart"
                                 cssClass="width-200-px" onclick="selectDate('lastValuationPeriodStart')" onKeyPress="return dateNumbersOnly(event,true)"/></td>
                <td><s:label value="Last Valuation Period End"/><span class="mandatory-field"></span></td>
                <td><s:textfield id="lastValuationPeriodEnd" name="alienation.valuation.lastValuationPeriodEnd"
                                 cssClass="width-200-px" onclick="selectDate('lastValuationPeriodEnd')" onKeyPress="return dateNumbersOnly(event,true)"/></td>
            </tr>

            <tr>

                <td><s:label value="Current Rental"/><span class="mandatory-field"></span></td>
                <td><s:textfield id="annualRental" cssClass="width-200-px"
                                             name="alienation.leaseDetail.annualRental"
                                             onKeyPress="return false" /></td>
                <td><s:label value="Current Tax"/><span class="mandatory-field"></span></td>
                <td><s:textfield id="annualTax" cssClass="width-200-px"
                                             name="alienation.leaseDetail.annualTax"
                                             onKeyPress="return false"/>
                <s:hidden id="taxPercentage" name="taxPercent" />
                </td>
            </tr>
            <tr>
                <td><s:label value="Arrears Amount"/></td>
                <td><s:textfield id="arrearsAmount" cssClass="width-200-px"
                                             name="alienation.leaseDetail.arrearsAmount"
                                             onKeyPress="return dateNumbersOnly(event,true)"/></td>
                <td><s:label value="Arrears Tax"/></td>
                <td><s:textfield id="arrearsTax" cssClass="width-200-px"
                                             name="alienation.leaseDetail.arrearsTax"
                                             onKeyPress="return dateNumbersOnly(event,true)"/></td>
            </tr>
            <tr>
                <td><s:label value="Paid Amount"/></td>
                <td><s:textfield id="paidAmount" cssClass="width-200-px"
                                             name="alienation.leaseDetail.paidAmount"
                                             onKeyPress="return dateNumbersOnly(event,true)"/></td>
                <td><s:label value="Paid Tax"/></td>
                <td><s:textfield id="paidTax" cssClass="width-200-px"
                                             name="alienation.leaseDetail.paidTax"
                                             onKeyPress="return dateNumbersOnly(event,true)"/>
                    <s:hidden name="alienation.leaseDetail.version" id="leaseDetailVersion"/>
                </td>

            </tr>




            <tr>
                <td><s:label value="Added Valuation"/></td>
                <td>
                    <s:checkbox id="valuePercent" label="Add" name="alienation.valuation.valuationOption" value="alienation.valuation.valuationOption" fieldValue="true"/>
                    <s:hidden name="alienation.valuation.version" id="leaseDetailVersion"/>
                </td>
                <td><s:label value="Percentage"/></td>
                <td><s:textfield id="valuationPercentage" name="alienation.valuation.addedPercentage" cssClass="width-150-px" onKeyPress="return dateNumbersOnly(event,true)" /></td>
            </tr>
        </table>
    </div>

    <div id="personal-details">
        <table class="width-100">
            <tr>
                <td align="center" colspan="4">
                    <s:radio id="clientType" name="alienation.holder.holderType"
                             list="#@java.util.HashMap@{'1':getText('person.label'),'0':getText('institute.label')}"
                             value="1"/>
                    <%--<s:if test="land.mode.ordinal() == 1">--%>
                        <s:hidden id="c-type" name="alienation.holder.holderType" disabled="true"/>
                    <%--</s:if>--%>
                </td>
            </tr>
        </table>
        <table id="holderInstitute" class="width-100">
            <tr>
                <td><s:label value="Institute Type"/><span class="mandatory-field"></span></td>
                <td colspan="3"><s:select id="instituteId" name="alienation.holder.institute.id" list="instituteList"
                                          headerKey="0"
                                          headerValue="%{getText('select.label')}" cssClass="width-240-px"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('name_of_institute.label')}"/><span class="mandatory-field"></span></td>
                <td colspan="3"><s:textarea id="name" name="alienation.holder.name" cssClass="width-595-px"
                                            rows="1"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('address.label')}"/></td>
                <td colspan="3"><s:textarea id="address" name="alienation.holder.contacts.address"
                                            cssClass="width-595-px"
                                            rows="1"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('registration_no.label')}"/></td>
                <td colspan="3"><s:textfield id="nic" name="alienation.holder.registrationNumberOrNIC"
                                             cssClass="width-200-px"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('contact_number.label')}"/></td>
                <td><s:label value="%{getText('mobile.label')}"/></td>
                <td><s:textfield id="mobile" name="alienation.holder.contacts.mobile" cssClass="width-200-px"/></td>
            </tr>
            <tr>
                <td></td>
                <td><s:label value="%{getText('land_line.label')}"/></td>
                <td><s:textfield id="landPhone" name="alienation.holder.contacts.landPhone"
                                 cssClass="width-200-px"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('email.label')}"/></td>
                <td colspan="3"><s:textfield id="email" name="alienation.holder.contacts.email"
                                             cssClass="width-200-px"/></td>
            </tr>
            <tr>
                <td><s:label value="%{getText('fax.label')}"/></td>
                <td colspan="3"><s:textfield id="fax" name="alienation.holder.contacts.fax"
                                             cssClass="width-200-px"/></td>
            </tr>
        </table>
        <table id="holderPerson" class="width-100">
            <tr>
                <td>
                    <s:include value="personalDetails.jsp"/>
                </td>
            </tr>
        </table>
    </div>
    <div id="occupier-details">
        <table class="width-100">
            <s:include value="encroacherDetails.jsp"/>
        </table>
    </div>
</div>

<table class="width-100" id="commentOnAlienation">


    <tr>
        <td><s:label value="%{getText('comment_about_alienation.label')}"/></td>

        <s:if test="(user.role.id != \"SC\")">
            <td colspan="3"><s:textarea id="alienationComment" name="alienation.alienationComment"
                                        cssClass="width-595-px" rows="1" disabled="true"/></td>
        </s:if>
        <s:else>
            <td colspan="3"><s:textarea id="alienationComment" name="alienation.alienationComment"
                                        cssClass="width-595-px" rows="1"/></td>
        </s:else>
        <s:hidden name="alienation.version"/>
    </tr>
</table>

<s:hidden name="alienation.id"/>
<s:hidden name="alienation.holder.id"/>
<s:hidden name="alienation.holder.contacts.id"/>
<s:hidden name="alienation.leaseDetail.id"/>
<s:hidden name="alienation.valuation.id"/>


<s:hidden id="pls_enter_reference_no" value="%{getText('pls_enter_reference_no')}"/>
<s:hidden id="pls_enter_name_of_the_land" value="%{getText('pls_enter_name_of_the_land')}"/>
<s:hidden id="pls_enter_plan_no" value="%{getText('pls_enter_plan_no')}"/>
<s:hidden id="pls_enter_lot_no" value="%{getText('pls_enter_lot_no')}"/>
<s:hidden id="pls_enter_valid_no" value="%{getText('pls_enter_valid_no')}"/>
<s:hidden id="pls_select_gn_division" value="%{getText('pls_select_gn_division')}"/>

<s:hidden id="enterChildName" value="%{getText('enter_child_name.label')}"/>
<s:hidden id="enterEncroacherName" value="%{getText('enter_encroacher_name.label')}"/>